package com.cq.hd.member.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbMerchantApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import com.cq.hd.member.service.TbMerchantService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商户表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@RestController
public class TbMerchantController implements TbMerchantApi {

    @Autowired
    private TbMerchantService merchantService;

    @ApiOperation(value = "商户列表")
    @ApiImplicitParam(name = "merchantPageDto", value = "实体", required = true, paramType = "query", dataType = "MerchantPageDto")
    @ApiResponse(response = MerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<MerchantPageVo>> pageMerchant(MerchantPageDto merchantPageDto) {
        return ResultGenerator.success(merchantService.pageMerchant(merchantPageDto));
    }

    @ApiOperation(value = "商户详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = AdminMerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AdminMerchantPageVo> details(Long id) {
        return ResultGenerator.success(merchantService.details(id));
    }

    @ApiOperation(value = "关联商家列表")
    @ApiImplicitParam(name = "relationBusinessPageDto", value = "实体", required = true, paramType = "query", dataType = "RelationBusinessPageDto")
    @ApiResponse(response = RelationBusinessPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<RelationBusinessPageVo>> pageRelationBusiness(RelationBusinessPageDto relationBusinessPageDto) {
        return ResultGenerator.success(merchantService.pageRelationBusiness(relationBusinessPageDto));
    }

    @ApiOperation(value = "根据手机号获取商户信息")
    @ApiImplicitParam(name = "mobile", value = "手机号", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = MerchantVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<MerchantVo> getByMobile(String mobile) {
        return ResultGenerator.success(merchantService.getByMobile(mobile));
    }

    @ApiOperation(value = "根据商户id获取商户信息")
    @ApiImplicitParam(name = "id", value = "实体", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = MerchantVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<MerchantVo> getById(long id) {
        return ResultGenerator.success(merchantService.getMerchantById(id));
    }

    @ApiOperation(value = "更新商户数据")
    @Override
    public Result<Boolean> updateMerchant(@RequestBody MerchantUpdateDto merchantUpdateDto) {
        return ResultGenerator.success(merchantService.updateMerchant(merchantUpdateDto));
    }

    @ApiOperation(value = "app商户列表")
    @ApiImplicitParam(name = "appMerchantPageDto", value = "实体", required = true, paramType = "query", dataType = "AppMerchantPageDto")
    @ApiResponse(response = AppMerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<AppMerchantPageVo>> pageAppMerchant(AppMerchantPageDto appMerchantPageDto) {
        return ResultGenerator.success(merchantService.pageAppMerchant(appMerchantPageDto));
    }

    @ApiOperation(value = "商户详情")
    @ApiImplicitParam(name = "appMerchantDetailDto", value = "实体", required = true, paramType = "query", dataType = "AppMerchantDetailDto")
    @ApiResponse(response = AppMerchantDetailVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppMerchantDetailVo> detailAppMerchant(AppMerchantDetailDto appMerchantDetailDto) {
        return ResultGenerator.success(merchantService.detailAppMerchant(appMerchantDetailDto));
    }

    @ApiOperation(value = "根据商户id批量获取商户数据")
    @ApiResponse(response = MerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<MerchantPageVo>> listByIds(@RequestBody List<String> ids) {
        return ResultGenerator.success(merchantService.listMerchantByIds(ids));
    }

    @ApiOperation(value = "根据openId获取商户数据")
    @Override
    public Result<MerchantVo> getByOpenId(String openid) {
        return ResultGenerator.success(merchantService.getByOpenId(openid));
    }

    @ApiOperation(value = "更新客服信息")
    @Override
    public Result<Boolean> updateCustomInfo(@RequestBody MerchantCustomUpdateDto merchantCustomUpdateDto) {
        return ResultGenerator.success(merchantService.updateCustomInfo(merchantCustomUpdateDto));
    }

    @ApiOperation(value = "修改登录密码")
    @Override
    public Result<Boolean> updatePwd(@RequestBody MerchantPwdUpdateDto merchantPwdUpdateDto) {
        return ResultGenerator.success(merchantService.updatePwd(merchantPwdUpdateDto));
    }

    @ApiOperation(value = "根据日期查询新入驻的商户数")
    @Override
    public Result<Integer> getNewCountByDate(String startTime, String endTime) {
        return ResultGenerator.success(merchantService.getNewCountByDate(startTime, endTime));
    }

    @ApiOperation(value = "批量获取商户详情数据")
    @Override
    public Result<List<MerchantDetailVo>> listDetailByIds(@RequestBody List<Long> merchantIds) {
        return ResultGenerator.success(merchantService.listDetailByIds(merchantIds));
    }

    @ApiOperation(value = "增加商户的商户本金和商户补贴金额")
    @Override
    public Result<Boolean> addMerchantAmt(@RequestBody MerchantAmtAddDto merchantAmtAddDto) {
        return ResultGenerator.success(merchantService.addMerchantAmt(merchantAmtAddDto));
    }

    @Override
    public Result<Boolean> updateBankCard(MerchantBankCardDto merchantBankCardDto) {
        return ResultGenerator.success(merchantService.updateBankCard(merchantBankCardDto));
    }

    @Override
    public Result<MerchantBankCardVo> getBankCard(Long merchantId) {
        return ResultGenerator.success(merchantService.getBankCard(merchantId));
    }
}
